<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/14
  Time: 11:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Sheraton酒店管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all" />

</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户姓名:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="userName" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入用户姓名" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">用户邮箱:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="email" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入用户邮箱" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="starttime" id="createtime1" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入开始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="endtime" id="createtime2" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label"></label>
            <div class="layui-input-inline" style="padding: 5px">
                <button   class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm" lay-submit  lay-filter="doSearch">查询
                </button>
                <button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm">重置
                </button>
            </div>
        </div>
    </div>

</form>
<!-- 搜索条件结束 -->
<table id="newsTable" lay-filter="newsTable"></table>

<script id="toolbarNews" type="text/html">
    <div class="layui-btn-container">
       <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="delBatch">批量删除</button>
    </div>
</script>

<script id="barNews" type="text/html">
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs layui-btn-radius" lay-event="showNews">查看</a>
</script>
<%-- 添加或者修改弹出框结束 --%>
<%--查看公告的div开始--%>
<div id="viewNewsDiv" style="padding: 10px;display: none">
    <h2 id="view_title" align="center"></h2>
    <h2 id="view_phone" align="center"></h2>
    <hr>
    <div style="text-align: right">
        用户邮箱:<span id="view_email"></span>
        <span style="display: inline-block;width: 20px"></span>
        发布时间:<span id="view_createtime"></span>
    </div>
    <hr>
    <div id="view_content"></div>
</div>
<%--查看公告的div结束--%>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>

    var newsTable;
    var index
    var layeditContent
    layui.use(['table','form','layer','jquery','laydate','layedit'], function() {
        var table = layui.table
        var form = layui.form
        var layer = layui.layer
        var $ = layui.jquery
        var laydate = layui.laydate;
        var layedit = layui.layedit;
        //执行一个laydate实例
        laydate.render({
            elem: '#createtime1' //指定元素
            , type: "datetime"
        });

        laydate.render({
            elem: '#createtime2' //指定元素
            , type: "datetime"
        });
        // 初始table
        newsTable = table.render({
            elem: "#newsTable"
            , url: "${pageContext.request.contextPath}/advice/adviceShow"
            , page: {limit: 5, limits: [5, 10, 15]} //开启分页
            , cellMinWidth: 80
            , toolbar: '#toolbarNews' //开启头部工具栏，并为其绑定左侧模板
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'adviceId', title: '评论ID', fixed: 'center'}
                , {field: 'userName', title: '用户姓名', fixed: 'center'}
                , {field: 'email', title: '用户邮箱', fixed: 'center'}
                , {field: 'advice', title: '评论', fixed: 'center'}
                , {field: 'createTime', title: '创建时间', fixed: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#barNews'}
            ]]
        })

        // form表单提交  -- 查询功能
        form.on('submit(doSearch)', function (data) {
            //ajax数据
            newsTable.reload({
                where: data.field,
                page:{curr:1}
            })
            //不跳转页面
            return false;
        })

        // 头部工具栏添加事件
        table.on('toolbar(newsTable)', function (obj) {
            if (obj.event == "delBatch") { // 批量删除
                delBatch()
            }
        })

        function delBatch(){
            var data1 = table.checkStatus('newsTable').data
            // var data1=checkStatus.data;
            var ids="";
            var count=0;
            for(var i=0;i<data1.length;i++){
                ids+=data1[i].adviceId+",";
                count++;
            }
            if(count == 0){
                return;
            }
            ids = ids.substring(0,ids.length-1)
            layer.confirm("确定删除这"+count+"条数据吗",function(r){
                layui.$.get("${pageContext.request.contextPath}/advice/deleteAllAdvice?ids="+ids,function(rr){
                    layer.msg(rr.msg)
                    newsTable.reload()
                })
            })
        }

        <%--// form表达提交 -- 新增/修改--%>
        <%--form.on("submit(doSubmit)",function(d) {--%>
            <%--// 获取富文本上的内容--%>
            <%--layedit.getContent(layeditContent)--%>
            <%--layedit.sync(layeditContent) //  把富文本内容同步到textarea--%>
            <%--layer.confirm("您确定要提交该数据么",function(ind){--%>
                <%--$.post("${pageContext.request.contextPath}/annouce/newsAdd",$("#dataFrm").serialize(),function(data) {--%>
                    <%--layer.msg(data.msg)--%>
                    <%--layer.close(index)--%>
                    <%--// 刷新table数据--%>
                    <%--newsTable.reload()--%>

                <%--})--%>
                <%--layer.close(ind)--%>
            <%--})--%>
            <%--return false;--%>
        <%--})--%>


        //监听行工具事件
        table.on('tool(newsTable)', function (obj) {
            var data = obj.data
            if (obj.event == "del") { // 删除
                deleteNews(data.adviceId)
            }else if (obj.event == "showNews") {
                checkContent(obj.data)
            }
        })
        function deleteNews(id){
            layer.confirm("确定要删除该数据吗？", function () {
                $.post("${pageContext.request.contextPath}/advice/adviceDelete", {"adviceId": id}, function (r) {
                    layer.msg(r.msg)
                    newsTable.reload()
                })
            })
        }

        // function newsEdit(data) {
        //     // 弹出框
        //     index =  layer.open({
        //         type:1 // 1（页面层）
        //         , title:"修改公告"
        //         , content:$("#saveOrUpdateDiv")
        //         , area : ['700px', '500px']
        //         , success:function() {
        //             form.val("dataFrm",data)
        //             // layeditContent = layedit.build('content'); //建立编辑器
        //             // layedit.setContent(layeditContent,data.content);
        //
        //
        //             layeditContent = layedit.build('content'); //建立编辑器
        //             // 顺序 赋值 ==> 渲染
        //             $("#content").val(data.content); //先赋值
        //             layedit.build('content');  //渲染 build
        //         }
        //     })
        // }

        function checkContent(data) {
            //打开弹出层
            index = layer.open({
                type: 1
                , title: '查看公告'
                , content: layui.$("#viewNewsDiv")
                , area: ['800px', '440px']
                , success: function () {

                    layeditContent = layedit.build('content'); //建立编辑器

                    // 顺序 赋值 ==> 渲染
                    $("#view_content").html(data.advice); //先赋值

                    $("#view_email").text(data.email)

                    $("#view_createtime").text(data.createTime)

                    $("#view_title").text(data.userName)

                    $("#view_phone").text(data.phone)
                    layedit.build('content');  //渲染 build
                }
            })
        }


    })


</script>
</body>
</html>

